#ifndef _MY_ARRAY_H
#define _MY_ARRAY_H


//#include <my_config.h>
//#include <my_core.h>


typedef struct {
    void        *elts;//
    uintptr_t   nelts;
    size_t       size;
    uintptr_t   nalloc;
    my_pool_t  *pool;
} my_array_t;


my_array_t *my_array_create(my_pool_t *p, uintptr_t n, size_t size);
void my_array_destroy(my_array_t *a);
void *my_array_push(my_array_t *a);
void *my_array_push_n(my_array_t *a, uintptr_t n);


static inline intptr_t
my_array_init(my_array_t *array, my_pool_t *pool, uintptr_t n, size_t size)
{
    /*
     * set "array->nelts" before "array->elts", otherwise MSVC thinks
     * that "array->nelts" may be used without having been initialized
     */

    array->nelts = 0;
    array->size = size;
    array->nalloc = n;
    array->pool = pool;

    array->elts = my_palloc(pool, n * size);
    if (array->elts == NULL) {
        return MY_ERROR;
    }

    return MY_OK;
}


#endif 